﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using YAPL.Language.Core.Types;

namespace YAPL.Language.Core {
	public class FunctionCollection : IEnumerable<YAPLFunction> {
		private readonly Dictionary<string, YAPLFunction> _functions = new Dictionary<string, YAPLFunction>();
		public YAPLFunction this[string key] {
			get {
				return !_functions.ContainsKey(key) ? _functions[FunctionNames.NoMethod] : _functions[key];
			}
			set {
				_functions[key] = value;
			}
		}

		public bool Defined(string key) {
			return _functions.ContainsKey(key);
		}

		public IEnumerator<YAPLFunction> GetEnumerator() {
			foreach (var pair in _functions) {
				yield return pair.Value;
			}
		}

		IEnumerator IEnumerable.GetEnumerator() {
			foreach (var pair in _functions) {
				yield return pair.Value;
			}
		}
	}
}
